;(function(){
	function weatherTotal(){
		 var weather = $("#today").data("value");
		 weather += ","+ $(".wt.active").data("value");
		 weather += ","+ $("#height").data("value");
		 if($("#weatherHigh:checked").length>0)
		 weather += ","+$("#weatherHigh:checked").data("value");
		 weather += ","+ $("#tp").val();
		 weather += ","+ $("#tmp").data("value");
		 weather += ","+ $("#low").data("value");
		if($("#weatherLow:checked").length>0)
		 	weather += ","+$("#weatherLow:checked").data("value");
		 weather += ","+ $("#td").val();
		 weather += ","+ $("#tmp").data("value");
		$("#weather-all").val(weather);
	 }
	// 今日天气
	$("today").click(function(){
		weatherTotal();
	})
	// 天气状况
	$(".wt").click(function(){

		$(".wt.active").removeClass("active");
		$(this).addClass("active");
		weatherTotal();
	})
	// 最高气温
	$("#height").click(function(){
		weatherTotal();
	})
	// 最高气温（零下）
	$("#weatherHigh").click(function(){
		weatherTotal();
	})
	// 最高气温
	$("#tp").on('input',function(){
		weatherTotal();
	})
	// 摄氏度
	$("#tmp").click(function(){
		weatherTotal();
	})
	// 最低气温
	$("#low").click(function(){
		weatherTotal();
	})
	// 最低气温（零下）
	$("#weatherLow").click(function(){
		weatherTotal();
	})
	// 最低气温
	$("#td").on('input',function(){
		weatherTotal();
	})
	$("#saves").click(function(){
		var token = $.cookie('token');
		var a = $("#dt .active #area").html();
		var b = $("#dt .active #area2").html();
		var param = $("#weather-all").val();
		var param2 = $("#weather-enter").val();
		var expire = $("#Wdate").val();
		var tp = $("#tp").val();
		var td = $("#td").val();
		if(param!=""&&param2!=""&&tp!=""&&td!=""){
			$.ajax({
				url:'/WebService1.asmx/AddWeatherV2',
				type:'post',
				headers:{'Content-Type':'application/x-www-form-urlencoded',},
				data:{token:token,area:a,area2:b,param:param,param2:param2,expire:expire},
				dataType:"text",
				async: false,
				success:function(){
					$.ajax({
						url:'/WebService1.asmx/SetDeviceFlagByArea',
						type:'post',
						async: false,
						headers:{'Content-Type':'application/x-www-form-urlencoded',},
						data:{token:token,area:a,area2:b},
						dataType:"text",
						success:function(){
							alert("添加成功");
						}
					})
				}
			})
		}
		else {alert("请输入正确的天气数据");$(".weather-top").fadeIn();$(".weather-mid").fadeIn();};
		
		
	})
	var mydateInput = document.getElementById("Wdate");
	var date = new Date();
	date.setDate(date.getDate()+1)
	var dateString = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
	mydateInput.value = dateString;
})();
